/*
 * Copyright (C) 2011 Michael Widmer <widmm8@bfh.ch>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ch.bfh.aeneas.navigation.find;

import android.content.Intent;
import android.location.Location;
import android.util.Log;
import ch.bfh.aeneas.exchange.intent.MalformedIntentException;
import ch.bfh.aeneas.navigation.app.NavigationService;
import ch.bfh.aeneas.exchange.Scope;

/**
 * This is the backing service of FindMe. It requests the addresses for the 
 * specified location from providers.
 * @author Michael Widmer <widmm8@bfh.ch>
 */
public class FindService extends NavigationService {

    private String LOG_TAG = "FindService";
    
    public void findMe(Location loc, long duration) {
        Intent i = super.getBroadcastIntent();
        i.putExtra("type", "geocode");
        i.putExtra("scope",Scope.BOTH);
        i.putExtra("coordinates", loc);
        
        try {
            super.broadcast(i, duration);
        } catch (MalformedIntentException ex) {
            Log.i(LOG_TAG, "Malformed Intent in sendRequest of FindService!");
        }
    }
    
    public void findMe(Location loc) {
        this.findMe(loc, 10000L);
    }
    
    @Override
    /**
     * {@inheritDoc}
     */
    protected void onAnswer(Intent i) {
        Log.i(LOG_TAG, "parsing answer");
        informOnResult(i);
    }    
}
